#ifndef __clib_trbtree_h__
#define __clib_trbtree_h__

#include "../container/rbtree.h"
#include <mem.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <time.h>

int int_cmp( void *i1, void *i2 )
{
	return *(int*)i1 - *(int*)i2;
}

void test_rbtree()
{
	rbtree *_rbt;
	int *_key;
	int _size = 10000000;
	int _count = 10000000;
	int _val = 1;
	int i;
	time_t t;
	_key = (int*)palloc( sizeof(int) * _size );
	srand( (uint32)time(NULL) );
	for( i = 0; i < _count; ++i )
	{
		_key[i] = rand()*rand();
	}

	t = time(NULL);
	_rbt = rbt_create( int_cmp );
	for( i = 0; i < _count; ++i )
	{
		rbt_insert( _rbt, _key+i, &_val );
	}
	printf( "use %ds\n", time(NULL)-t );
	t = time(NULL);
	for( i = 0; i < _count; ++i )
	{
		rbt_node *_rbtn;
		_rbtn = rbt_find( _rbt, _key+i );
		if( _rbtn == rbt_end( _rbt ) )
		{
			printf( "not found\n" );
		}
	}
	printf( "use %ds\n", time(NULL)-t );
	rbt_destroy( _rbt );
	pfree( _key );
}

#endif // __clib_trbtree_h__
